package br.com.appestoque.util;

import twitter4j.GeoLocation;
import twitter4j.StatusUpdate;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;

public class RedeSocial {
	
	public static void twittar( String consumerKey, String consumerSecret, 
			String accessToken, String accessTokenSecret, String tweet ) throws Exception {
		try{
			ConfigurationBuilder cb = new ConfigurationBuilder();
			cb.setDebugEnabled(true)
			  .setOAuthConsumerKey(consumerKey)
			  .setOAuthConsumerSecret(consumerSecret)
			  .setOAuthAccessToken(accessToken)
			  .setOAuthAccessTokenSecret(accessTokenSecret);
			TwitterFactory tf = new TwitterFactory(cb.build());
			Twitter twitter = tf.getInstance();
			twitter.updateStatus(tweet);			
		}catch(TwitterException e){
			throw new Exception(e.getErrorMessage());
		}
	}
	
	public static void twittar( String consumerKey, String consumerSecret, 
			String accessToken, String accessTokenSecret, String tweet, 
			double	latitude, double longitude ) throws Exception {
		try{
			ConfigurationBuilder cb = new ConfigurationBuilder();
			cb.setDebugEnabled(true)
			  .setOAuthConsumerKey(consumerKey)
			  .setOAuthConsumerSecret(consumerSecret)
			  .setOAuthAccessToken(accessToken)
			  .setOAuthAccessTokenSecret(accessTokenSecret);
			TwitterFactory tf = new TwitterFactory(cb.build());
			Twitter twitter = tf.getInstance();
			
			StatusUpdate statusUpdate = new StatusUpdate(tweet);
			GeoLocation geoLocation = new GeoLocation(latitude, longitude);			
			statusUpdate.setLocation(geoLocation);
			
			twitter.updateStatus(statusUpdate);
		}catch(TwitterException e){
			throw new Exception(e.getErrorMessage());
		}
	}
	
}